from fastapi import APIRouter

from app.database.postgre import SessionDep
from app.database.models import App
from app.models.common import AppIdJSON
from app.models import responses
from app.services import accounts
from app.utils.faker import generate_login_records

router = APIRouter(
    prefix='/api/v1/login_records',
    tags=['faker', 'login_records']
)


@router.post('/generate')
async def create_login_records(account: accounts.LoggedInAccount, json_data: AppIdJSON, session: SessionDep):
    # 验证超级管理员权限
    if not account.has_super_permission:
        return responses.Response202()

    app = session.get(App, json_data.app_id)
    if not app:
        return responses.Response303()

    generate_login_records(session, app.id, 50)

    return responses.SuccessResponse()
